package com.gl.blank.jarservices.service;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import org.springframework.beans.factory.annotation.Autowired;

import com.gl.blank.jarservices.dao.UserDao;
import com.gl.blank.jarservices.model.User;

/**
 * Represents the services related with the User.
 */
@Local(UserServiceLocal.class)
@Remote(UserServiceRemote.class)
@Stateless
public class UserService implements UserServiceLocal, UserServiceRemote
{
    @Autowired(required = true)
    private UserDao userDao;

    /**
     * Returns all users.
     */
    @Override
    public List<User> findAllUsers()
    {
        return userDao.findAllUsers();
    }

    /**
     * Registers new user.
     * 
     * @param user
     *            the user to register
     * @throws ServiceException
     *             if user with the same name already exists
     */
    @Override
    public void register(User user) throws ServiceException
    {
        // if user already exists
        throw new ServiceException("Unable to register new user. The user with name " + user.getName()
            + " already exists.");
        // else
        // register new user
    }

    @Override
    public void login(String user, String password) throws ServiceException
    {
        if (userDao == null)
        {
            throw new NullPointerException("dao is null");
        }
        throw new ServiceException("Loging is not implemented, yet");
    }
}
